package com.javalong.affairs.utils;


import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.Display;

public class DisplayUtils {
	private static DisplayMetrics outMetrics = null;

	public static void init(Activity activity) {
		outMetrics = new DisplayMetrics();
		Display display = activity.getWindowManager().getDefaultDisplay();
		display.getMetrics(outMetrics);
	}

	public static DisplayMetrics getOutMetrics() {
		return outMetrics;
	}

	public static void setOutMetrics(DisplayMetrics outMetrics) {
		DisplayUtils.outMetrics = outMetrics;
	}

	public static int dip2px(Context context, float dpValue) {
		final float scale = context.getResources().getDisplayMetrics().density;
		return (int) (dpValue * scale + 0.5f);
	}

	public static int px2dip(Context context, float pxValue) {
		final float scale = context.getResources().getDisplayMetrics().density;
		return (int) (pxValue / scale + 0.5f);
	}

}
